Quiz III Date: Thursday November 20 
Material: Up to and including the material covered on Thursday, November 13 (Post-exam material)

- Stack
LIFO data structure
Stack ADT: push, pop, top, size, isEmpty

Example: 

1. Create a stack data structure from scracth

1.a) Create the stack ADT
1.b) Create the exception classes
1.c) Create a class that implements the stack ADT
1.d) Test the methods of the class
1.e) Use the data structure to solve the problem at hand


Constraint: All method should be implemented to run in O(1) time

Array holding the values + keep track of the position of the top element with an initial value = -1

2. Use it to solve the grouping symbols problem

( Invalid; () valid;   valid; ([)] invalid; a + b valid; ([]) valid

opening: ([{
closing: )]}

Algorithm: 
a) Every time we encounter an opening symbol, push onto the stack
b) If we encounter a closing symbol, compare it to the top of the stack:
case#1: If the stack is empty ---> return false
case#2: If symbols are not of same nature ---> return false
case#3: perform a pop operation

Time complexity: O(n) and space complexity: O(n)

-------------------------------------------------------------------------------------
In Java, the double ended queue interface is called Deque ---> ArrayDeque + LinkedList
Queue:
FIFO data structure
ADT: size, isEmpty, enqueue, dequeue, front

O(1) running time

Implicit assumptions: If we have n elements in the queue, they will occupy the first n 
positions in the array

Option#1: 
Let the front element be stored at index 0
Array of size n to hold the queue elements --> valid indexes: 0 through n - 1
dequeue requires O(n) time
enqueue requires O(1) time

Option#2: 
Let the rear element be stored at index 0.

enqueue requires O(n) time
dequeue requires O(1) time

Option#3: 
Array of values + two additional indexes: 
1) front: index of the front element ---> front = 0 initially
2) rear: index of the next available cell in the queue

	front	rear
0	1	2
null	4	null


























